package com.shixianchen.review_the_day_before.day6;

import com.shixianchen.utils.Utils;

/**
 * @author ShiXianChen
 * @version V1.0.0
 * @Description 归并排序
 * @date 2022/11/9 21:35
 */
public class MergeSort {

    public static void main(String[] args) {
        int[] arr =  new int[]{2,4,6,9, 1,3,5,8,11};
        int[] result =  new int[arr.length];

        int pre = 0 ;
        int index = 0;
        int suf = 4;

        while(pre < 4 && suf < arr.length){
            if (arr[pre] <= arr[suf]) {
                result[index++] = arr[pre++];
            } else {
                result[index++] = arr[suf++];
            }

        }

        while (pre < 4) {
            result[index++] = arr[pre++];
        }
        while (suf < arr.length) {
            result[index++] = arr[suf++];
        }
        Utils.print(result);
    }

}
